<template>
	<view class="body">
		<!-- 门店搜索 -->
		<view class="seach" :style="{ height: headerHeight + 'rpx' }">
			<u-search placeholder="搜索门店" :show-action="false" class="search-input" v-model="query.search" @change="getshopList"></u-search>
		</view>
		<!-- 搜索列表 -->
		<scroll-view scroll-y="true" :style="{ height: 90 + 'vh' }">
			<list :seachList="seachList" @select="selectShop" v-if="seachList.length"></list>
			<empty v-else :content="'门店'"></empty>
		</scroll-view>
	</view>
</template>

<script>
	import list from './components/list.vue'
	import empty from '@/components/empty.vue'
	import {
		shopList
	} from '@/api/shop.js'
	export default {
		components: {
			list,
			empty
		},
		data() {
			return {
				windowHeight: uni.getSystemInfoSync().windowHeight,
				headerHeight: 106, // 假设的 header 高度
				query: {
					province:'',
					search:''
				},
				seachList: [],
				type:0
			}
		},
		computed: {
			scrollViewHeight() {
				return this.windowHeight - this.headerHeight;
			},
		},
		onLoad(e) {
			console.log('e', e);
			if(e.type){
				this.type = Number(e.type)
			}
			this.getshopList()
		},
		mounted() {

			uni.onWindowResize(this.onWindowResize);
		},
		beforeDestroy() {
			uni.offWindowResize(this.onWindowResize);
		},
		methods: {
			selectShop(item, index){
				console.log(item, index);		
				if(this.type){
					uni.navigateTo({
						url:'/pageA/shop/particulars?shop_id=' + item.shop_id
					})
				}else{
					uni.$emit('SHOPID', {shop_id:item.shop_id})
					uni.navigateBack({
						delta:2
					})
					
				}
			},
			getshopList(){
				shopList(this.query).then(({data:res})=>{
					console.log('res', res);
					if(res.code == 1){
						this.seachList = res.data.shop_list
					}
				})
			},
			// 监听窗口大小变化（可选）
			onWindowResize(res) {
				this.windowHeight = res.windowHeight;
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #e9e9e9;
	}

	.body {
		display: flex;
		flex-direction: column;

		.seach {
			width: 750rpx;
			// height: 106rpx;
			background: #ffffff;
			box-shadow: 0rpx 8rpx 28rpx 0rpx rgba(199, 205, 179, 0.15);
			display: flex;
			flex-direction: row;
			align-items: center;
			padding: 0 24rpx 0 40rpx;
		}

		.search-input {
			/* 基础样式 */
			width: 100%;
			height: 66rpx;
			background: #f6f6f6;
			border-radius: 16rpx;
			transition: width 0.3s ease;
			/* 宽度变化的过渡效果 */
		}
	}
</style>